﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RubberStopper : BaseObj
{
    public GameObject m_Target;
    public Transform m_FatherTarget;
    public Transform m_BigFather;

    bool OnPlatfrom;
    public override void OnReleseTrigger(NoloDeviceType handleType)
    {
        if (!OnPlatfrom)
        {
            base.OnReleseTrigger(handleType);
            transform.SetParent(m_BigFather);
        }
        else
        {
            OnRoundBottpmFlask();
        }
    }

    public void OnRoundBottpmFlask()
    {
        m_rigidbody.useGravity = false;
        m_rigidbody.isKinematic = true;
        m_collider.isTrigger = true;
        transform.position = m_Target.transform.position;
        transform.SetParent(m_FatherTarget);
        transform.rotation = Quaternion.Euler(0, 0, 0);
    }

    public void ResetParent()
    {
        transform.SetParent(m_BigFather);
    }

    public void OnGround()
    {
        m_rigidbody.useGravity = true;
        m_rigidbody.isKinematic = false;
        m_collider.isTrigger = false;
    }

    private void LateUpdate()
    {
        if (Vector3.Distance(m_Target.transform.position, transform.position) < 0.1f)
        {
            OnPlatfrom = true;
            RoundBottpmFlask.HaveStopper = true;

        }
        else
        {
            OnPlatfrom = false;
            RoundBottpmFlask.HaveStopper = false;
        }
    }

    //记录每个大步骤的初始状态
    #region
    public void SetBigStepTwo()
    {
        OnRoundBottpmFlask();
    }

    public void SetBigStepThree()
    {
        ResetPosition();
        ResetParent();
        OnGround();
    }

    public void SetBigStepFour()
    {
        ResetPosition();
        ResetParent();
        OnGround();
    }

    public void SetBigStepFive()
    {
        ResetParent();
        OnGround();
        transform.localPosition = new Vector3(-0.55f, 0.05f, 0);
    }
    #endregion  
}
